
var Tools={
      setCookie:function (name ,value,second){ //sencod秒
          var exp = new Date();
          exp.setTime(exp.getTime() + second*1000);
          document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
      },
      getCookie:function(name) {
          var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
          if(arr=document.cookie.match(reg))
              return unescape(arr[2]);
          else
              return null;
      },
      delCookie:function delCookie(name) {
         this.setCookie(name,"",-1)
      }

  };

var Network={
    domain:"http://114.132.223.140:8787",
    IP:"114.132.223.140:8787",
    geturl:function (url) { 
        var ttt=this.domain+url;
        return ttt;
     },
     get:function(url,data,success,error){
        this.commonsend(url,"get",data,success,error);
     },
     post:function(url,data,success,error){
        this.commonsend(url,"post",data,success,error);
     },
     aget:function(url,data,success,error){
        this.axiosCommon(url,"get",data,success,error);
     },
     apost:function(url,data,success,error){
        this.axiosCommon(url,"post",data,success,error);
     }, 
     commonsend:function (url,type,data,f1,f2) { 
        
        //  x-www-form-urlencode
         if (type == "get"){
            url=this.dealgeturl(data,url);
            $.ajax({
                url:url,
                type:type,
                error:function(err){
                    if(f2){
                        f2(err);
                    }
                    
                },
                success:function(res){
                    if(f1){
                        f1(res);
                    }
                    
                }
            });
            return;
         }
         url=this.geturl(url);
         data=this.dealpostdata(data);
            $.ajax({
                url:url,
                type:type,
                data:data,
                error:function(err){
                    if(f2){
                        f2(err); 
                    }
                      
                },
                success:function(res){
                    if(f1){
                        f1(res);
                    }
                    
                }
            });
      },
     axiosCommon:function (url,type,data,f1,f2) {
         //application/json
         //Form表格则是 form-data
        if(type=="post"){
        url=this.geturl(url);
        data=this.dealpostdata(data);
        console.log(url,data);
        axios.post(url,data).then(function (res) {f1(res);}).catch(function (err) {f2(err);});
        return;
        }
        url=this.dealgeturl(data,url);
        axios.get(url).then(function (res) {f1(res);}).catch(function (err) {f2(err);});
    
     },
     dealgeturl:function (data,url) {
         url=this.geturl(url);
         if($.isEmptyObject(data)  || data.constructor!=Object){
             return url
         }

        // var extra={name:"liuhangkai",age:10,"www":"xxx"};//额外补充参数
        // for (var key in extra){
        //     data[key]=extra[key];
        // }

        
         var _result=[];
         for(var key in data){
             var value=data[key];
             if(value.constructor ==Array){
                 value.forEach(function (_value) {
                    _result.push(key+"="+_value); 
                 });
             }else{
                 _result.push(key+"="+value);
             }
         }
         var temp= url+"?"+_result.join("&");
      
         return temp;
     },
     dealpostdata:function (data) {

        // var extra={name:"liuhangkai",age:10,"www":"xxx"};//额外补充参数
        // for (var key in extra){
        //     data[key]=extra[key];
        // }
         
        return data;
     },
     alert:function(msg,f){
        $.messager.alert('提示',msg,'info',function(){
                   if(f){
                       f();
                   }
        });
     },
     totast:function (msg) {
         $.messager.show({
            title:'提示',
            msg:msg,
            timeout:4000,
            showType:'slide'});
     },
     confirm:function (msg,f) {
        $.messager.confirm('确认', msg, function(r){
                if(f){
                    f(r);
                }
        });
     }

}




